package edu.ccut.saturn.studio.wfg.dialog.subactivitydialog;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

import edu.ccut.saturn.studio.Activator;
import edu.ccut.saturn.studio.Images;
import edu.ccut.saturn.studio.core.search.SaturnFileSearcher.SearchResult;
import edu.ccut.saturn.studio.core.search.dialog.OneCompontentSearchDialog;
import edu.ccut.saturn.studio.core.util.eclipse.Messages;
import edu.ccut.saturn.studio.core.util.eclipse.SaturnValidation;
import edu.ccut.saturn.studio.wfg.dialog.RevertCandidate;
import edu.ccut.saturn.studio.wfg.dialog.SelectionCandidate;
import edu.ccut.saturn.studio.wfg.dialog.TableViewerContentProvider;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.FormDataAttributeLabelProvider;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.MyCellModifierFormDataAttribute;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.SaturnFormDataDialogForAdd;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.SaturnFormDataDialogForDoubleClick;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.SaturnFormDataDialogForEdit;
import edu.ccut.saturn.studio.wfg.wfgmodel.FormDataAttribute;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnAttribute;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnSubActivityNode;

public class SaturnSubActivityDialog extends TitleAreaDialog {
	

	private SaturnSubActivityNode saturnSubActivityNode;
	
	// 基本信息
	private Label activityIdLabel, activityNameLabel, polymeModeLabel, descriptionLabel;

	private Text activityIdText, activityNameText, descriptionText;

	private Combo polymeModeCombo;
	
	
	// 扩展属性
	private Label subProcessLabel, imageLabel, transferModeLabel;
	
	private Text subProcessText;
	
	private Combo transferModeCombo;
	
	private boolean serach = false;
	
	// 参数(formData)
	private List<SaturnAttribute> formDataTemp;
	
	private TableViewer tableViewer_2;

	private Table table_2;
	
	private Button insertButton_2, deleteButton_2, upbutton_2, downbutton_2,editButton_2;

	public SaturnSubActivityDialog(Shell parentShell, SaturnSubActivityNode saturnSubActivityNode) {
		super(parentShell);
		this.saturnSubActivityNode = saturnSubActivityNode;
		this.copyFormDataList(saturnSubActivityNode.getFormDataAttributeList());
	}
	
	protected Control createContents(Composite parent) {
		Control contents = super.createContents(parent);
		setMessage(SelectionCandidate.SETTING_ATTRIBUTE + saturnSubActivityNode.getName()); 
		return contents;
	}
	
	@Override
	protected Control createDialogArea(Composite parent) {
	
		getShell().setText(SelectionCandidate.ATTRIBUTE_SETTING); 
		setTitleImage(Activator.getImage(Images.SATURN_ICONS_MAXNAME)); //$NON-NLS-1$
		Composite area = (Composite) super.createDialogArea(parent);
		
		TabFolder tabFolder;
		tabFolder = new TabFolder(area, SWT.NONE);
		tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
	
		// 基本信息选项卡
		final TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
		tabItem.setText(Messages.getString("SaturnSubActivityDialog.BaseInformation")); //$NON-NLS-1$
		
		final Group group = new Group(tabFolder, SWT.NONE);
		group.setText(Messages.getString("SaturnSubActivityDialog.BaseInformtionDefine")); //$NON-NLS-1$
		tabItem.setControl(group);
		final GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		group.setLayout(gridLayout);
		
		activityIdLabel = new Label(group, SWT.NONE);
		activityIdLabel.setText(Messages.getString("SaturnSubActivityDialog.ActionID")); //$NON-NLS-1$
		
		activityIdText = new Text(group, SWT.BORDER | SWT.READ_ONLY);
		activityIdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		activityNameLabel = new Label(group, SWT.NONE);
		activityNameLabel.setText(Messages.getString("SaturnSubActivityDialog.ActionName")); //$NON-NLS-1$

		activityNameText = new Text(group, SWT.BORDER);
		activityNameText.setTextLimit(50);
		activityNameText.setFocus();
		activityNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		polymeModeLabel = new Label(group, SWT.NONE);
		polymeModeLabel.setText(Messages.getString("SaturnSubActivityDialog.CollectPattern")); //$NON-NLS-1$

		polymeModeCombo = new Combo(group, SWT.READ_ONLY);
		polymeModeCombo.setLayoutData(new GridData(126, SWT.DEFAULT));
		polymeModeCombo.setItems(SelectionCandidate.polymeModeCandidate);

		descriptionLabel = new Label(group, SWT.NONE);
		descriptionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
		descriptionLabel.setText(Messages.getString("SaturnSubActivityDialog.Desription")); //$NON-NLS-1$

		descriptionText = new Text(group, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
		descriptionText.setTextLimit(200);
		final GridData gd_descriptionText = new GridData(SWT.FILL, SWT.FILL, true, true);
		gd_descriptionText.heightHint = 70;
		descriptionText.setLayoutData(gd_descriptionText);
	
		// 扩展属性选项卡
		final TabItem tabItem_1 = new TabItem(tabFolder, SWT.NONE);
		tabItem_1.setText(Messages.getString("SaturnSubActivityDialog.ExtendPattern")); //$NON-NLS-1$
	
		final Group group_1 = new Group(tabFolder, SWT.NONE);
		group_1.setText(Messages.getString("SaturnSubActivityDialog.ExtendAttribute")); //$NON-NLS-1$
		tabItem_1.setControl(group_1);
		final GridLayout gridLayout_1 = new GridLayout();
		gridLayout_1.numColumns = 3;
		group_1.setLayout(gridLayout_1);
		
		subProcessLabel = new Label(group_1, SWT.NONE);
		subProcessLabel.setText(Messages.getString("SaturnSubActivityDialog.SubFolw")); //$NON-NLS-1$

		subProcessText = new Text(group_1, SWT.BORDER);
		subProcessText.setTextLimit(150);
		subProcessText.setFocus();
		subProcessText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		
		imageLabel = new Label(group_1, SWT.NONE);
		imageLabel.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				OneCompontentSearchDialog searchDialog = new OneCompontentSearchDialog(
						Display.getDefault().getShells()[0],saturnSubActivityNode);
				
				if (searchDialog.open() == Window.OK) {
					subProcessText.setText(((SearchResult)searchDialog.getFirstResult()).getKey());
				}
			}
		});
		imageLabel.addMouseTrackListener(new MouseTrackAdapter() {
			public void mouseEnter(final MouseEvent e) {
				imageLabel.setImage(Activator.getImage(Images.AMPLIFY_MINUS)); //$NON-NLS-1$
			}
			public void mouseExit(final MouseEvent e) {
				imageLabel.setImage(Activator.getImage(Images.AMPLIFY_PLUS)); //$NON-NLS-1$
			}
		});
		imageLabel.setImage(Activator.getImage(Images.AMPLIFY_PLUS)); //$NON-NLS-1$

		transferModeLabel = new Label(group_1, SWT.NONE);
		transferModeLabel.setText(Messages.getString("SaturnSubActivityDialog.CallModel")); //$NON-NLS-1$

		transferModeCombo = new Combo(group_1, SWT.READ_ONLY);
		transferModeCombo.setLayoutData(new GridData(126, SWT.DEFAULT));
		transferModeCombo.setItems(new String[] {"同步", "异步"});
		
		
		
		// 参数选项卡(formData表单信息)
		final TabItem tabItem_2 = new TabItem(tabFolder, SWT.NONE);
		tabItem_2.setText(Messages.getString("SaturnSubActivityDialog.Parameter")); //$NON-NLS-1$

		final Group group_2 = new Group(tabFolder, SWT.NONE);
		group_2.setText(Messages.getString("SaturnSubActivityDialog.ParameterDefine")); //$NON-NLS-1$
		tabItem_2.setControl(group_2);
		final GridLayout gridLayout_2 = new GridLayout();
		group_2.setLayout(gridLayout_2);

		Composite composite2 = new Composite(group_2, SWT.NONE);
		final GridData gd_composite2 = new GridData(SWT.FILL, SWT.FILL, true, true);
		composite2.setLayoutData(gd_composite2);
		composite2.setLayout(new FormLayout());

		tableViewer_2 = new TableViewer(composite2, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
		tableViewer_2.addDoubleClickListener(new IDoubleClickListener() {
			public void doubleClick(final DoubleClickEvent arg0) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				SaturnAttribute attribute = (SaturnAttribute) selection.getFirstElement();
				openFormDataDialogFromDoubleClick(attribute);
			}
		});
		table_2 = tableViewer_2.getTable();
		final FormData fd_table_2 = new FormData();
		fd_table_2.bottom = new FormAttachment(100, -60);
		fd_table_2.right = new FormAttachment(100, -100);
		fd_table_2.top = new FormAttachment(0, 10);
		fd_table_2.left = new FormAttachment(0, 5);
		table_2.setLayoutData(fd_table_2);
		table_2.setLinesVisible(true);
		table_2.setHeaderVisible(true);
		tableViewer_2.setContentProvider(new TableViewerContentProvider());
		tableViewer_2.setLabelProvider(new FormDataAttributeLabelProvider());
		
		tableViewer_2.setColumnProperties(new String[] { "id", "key", "name", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
				"type", "accessType", "required" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		CellEditor[] cellEditor = new CellEditor[6];
		cellEditor[0] = null;
		cellEditor[1] = new TextCellEditor(tableViewer_2.getTable());
		cellEditor[2] = new TextCellEditor(tableViewer_2.getTable());
		cellEditor[3] = new ComboBoxCellEditor(tableViewer_2.getTable(),
				SelectionCandidate.formDataTypes, SWT.READ_ONLY);
		cellEditor[4] = new ComboBoxCellEditor(tableViewer_2.getTable(),
				SelectionCandidate.formDataReadWrite, SWT.READ_ONLY);
		cellEditor[5] = new ComboBoxCellEditor(tableViewer_2.getTable(),
				SelectionCandidate.formDataRequired, SWT.READ_ONLY);

		tableViewer_2.setCellEditors(cellEditor);
		tableViewer_2.setCellModifier(new MyCellModifierFormDataAttribute(tableViewer_2));

		final TableColumn newColumnTableColumn_id = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_id.setWidth(80);
		newColumnTableColumn_id.setText("ID"); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_0 = new TableColumn(table_2,	SWT.NONE);
		newColumnTableColumn_0.setWidth(80);
		newColumnTableColumn_0.setText(Messages.getString("SaturnSubActivityDialog.Expression")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_1 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_1.setWidth(80);
		newColumnTableColumn_1.setText(Messages.getString("SaturnSubActivityDialog.Name")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_2 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_2.setWidth(80);
		newColumnTableColumn_2.setText(Messages.getString("SaturnSubActivityDialog.Type")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_3 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_3.setWidth(80);
		newColumnTableColumn_3.setText(Messages.getString("SaturnSubActivityDialog.ReadType")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_4 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_4.setWidth(80);
		newColumnTableColumn_4.setText(Messages.getString("SaturnSubActivityDialog.IsNeed")); //$NON-NLS-1$

		insertButton_2 = new Button(composite2, SWT.NONE);
		insertButton_2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				openFormDataDialog();
			}
		});
		final FormData fd_addbutton_2 = new FormData();
		fd_addbutton_2.bottom = new FormAttachment(table_2, 23, SWT.TOP);
		fd_addbutton_2.top = new FormAttachment(table_2, 0, SWT.TOP);
		fd_addbutton_2.right = new FormAttachment(100, -20);
		fd_addbutton_2.left = new FormAttachment(100, -75);
		insertButton_2.setLayoutData(fd_addbutton_2);
		insertButton_2.setText(SelectionCandidate.INSERT_BUTTON); 

		deleteButton_2 = new Button(composite2, SWT.NONE);
		deleteButton_2.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked") //$NON-NLS-1$
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_DELETE_RECORD);  
				} else {
					SaturnAttribute fdAttribute = (SaturnAttribute) selection.getFirstElement();
					formDataTemp.remove(fdAttribute);
					orderFormData(formDataTemp);
					tableViewer_2.setInput(formDataTemp);
				}
			}
		});
		final FormData fd_deletebutton_2 = new FormData();
		fd_deletebutton_2.top = new FormAttachment(insertButton_2, 5, SWT.BOTTOM);
		fd_deletebutton_2.right = new FormAttachment(insertButton_2, 0, SWT.RIGHT);
		fd_deletebutton_2.left = new FormAttachment(100, -75);
		deleteButton_2.setLayoutData(fd_deletebutton_2);
		deleteButton_2.setText(SelectionCandidate.DELETE_BUTTON); 

		upbutton_2 = new Button(composite2, SWT.NONE);
		upbutton_2.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked") //$NON-NLS-1$
			public void widgetSelected(final SelectionEvent selectionevent) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					SaturnAttribute fdAttribute = (SaturnAttribute) selection.getFirstElement();
					Table table = tableViewer_2.getTable();
					if (tableViewer_2.getTable() != null) {
						int i = table.getSelectionIndex();
						if (i > 0) {
							formDataTemp.remove(fdAttribute);
							formDataTemp.add(i - 1, fdAttribute);
							orderFormData(formDataTemp);
							tableViewer_2.setInput(formDataTemp);
							table.setSelection(i - 1);
						}
					}
				}
			}
		});
		final FormData fd_upbutton_2 = new FormData();
		fd_upbutton_2.top = new FormAttachment(deleteButton_2, 5, SWT.BOTTOM);
		fd_upbutton_2.right = new FormAttachment(deleteButton_2, 0, SWT.RIGHT);
		fd_upbutton_2.left = new FormAttachment(100, -75);
		upbutton_2.setLayoutData(fd_upbutton_2);
		upbutton_2.setText(SelectionCandidate.UP_BUTTON); 

		downbutton_2 = new Button(composite2, SWT.NONE);
		downbutton_2.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked") //$NON-NLS-1$
			public void widgetSelected(final SelectionEvent selectionevent) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					SaturnAttribute fdAttribute = (SaturnAttribute) selection.getFirstElement();
					Table table = tableViewer_2.getTable();
					int i = table.getSelectionIndex();
					if (i < tableViewer_2.getTable().getItemCount() - 1) {
						formDataTemp.remove(fdAttribute);
						formDataTemp.add(i + 1, fdAttribute);
						orderFormData(formDataTemp);
						tableViewer_2.setInput(formDataTemp);
						table.setSelection(i + 1);
					}
				}
			}
		});
		final FormData fd_downbutton_2 = new FormData();
		fd_downbutton_2.top = new FormAttachment(upbutton_2, 5, SWT.BOTTOM);
		fd_downbutton_2.right = new FormAttachment(upbutton_2, 0, SWT.RIGHT);
		fd_downbutton_2.left = new FormAttachment(100, -75);
		downbutton_2.setLayoutData(fd_downbutton_2);
		downbutton_2.setText(SelectionCandidate.DOWN_BUTTON); 

		editButton_2 = new Button(composite2, SWT.NONE);
		editButton_2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent selectionevent) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_EDIT_RECORD);  
				} else {
					editFormDataDialog((FormDataAttribute) selection.getFirstElement());
					tableViewer_2.refresh();
				}
			}
		});
		final FormData fd_editbutton_2 = new FormData();
		fd_editbutton_2.top = new FormAttachment(downbutton_2, 5, SWT.BOTTOM);
		fd_editbutton_2.right = new FormAttachment(downbutton_2, 0, SWT.RIGHT);
		fd_editbutton_2.left = new FormAttachment(100, -75);
		editButton_2.setLayoutData(fd_editbutton_2);
		editButton_2.setText(SelectionCandidate.EDIT_BUTTON); 
		
		initial();
		
		/**
		 * 活动名称不能为空
		 * 
		 * */
		activityNameText.addModifyListener(new ModifyListener() {
			public void modifyText(final ModifyEvent e) {
				if("".equals(activityNameText.getText().trim())){ //$NON-NLS-1$
					setErrorMessage(Messages.getString("SaturnSubActivityDialog.ActionCannotEmpty")); //$NON-NLS-1$
					getButton(IDialogConstants.OK_ID).setEnabled(false);
				} else {
					setErrorMessage(null);
					getButton(IDialogConstants.OK_ID).setEnabled(true);
				}
			}
		});
		
		/**
		 * 子流程不能为空
		 * 
		 * */
		subProcessText.addModifyListener(new ModifyListener(){
			public void modifyText(ModifyEvent e) {
				if (Messages.getString("SaturnSubActivityDialog.25").equals(subProcessText.getText().trim())){ //$NON-NLS-1$
					setErrorMessage(Messages.getString("SaturnSubActivityDialog.SubActivityLimit")); //$NON-NLS-1$
					getButton(IDialogConstants.OK_ID).setEnabled(false);
				} else {
					setErrorMessage(null);
					getButton(IDialogConstants.OK_ID).setEnabled(true);			
				}
			}	
		});
		
		return area;
	}
	
	
	protected Point getInitialSize() {
		return new Point(540, 480);
	}
	
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(SelectionCandidate.ATTRIBUTE_SETTING); 
		newShell.setImage(Activator.getImage(Images.SATURN_ICONS_SMALLNAME));  //$NON-NLS-1$
	}
	
	protected int getShellStyle() {
		return SWT.CLOSE | SWT.RESIZE;
	}
	
	private void openFormDataDialog() {
		SaturnFormDataDialogForAdd addDialog = new SaturnFormDataDialogForAdd(Display.getDefault().getShells()[0], formDataTemp, saturnSubActivityNode);
		if (addDialog.open() == IDialogConstants.OK_ID) {
			tableViewer_2.setInput(formDataTemp);
		}
	}
	
	private void editFormDataDialog(FormDataAttribute form) {
		SaturnFormDataDialogForEdit editDialog = new SaturnFormDataDialogForEdit(Display
				.getDefault().getShells()[0], form, saturnSubActivityNode);
		editDialog.open();
	}
	
	public void openFormDataDialogFromDoubleClick(SaturnAttribute attribute) {
		SaturnFormDataDialogForDoubleClick dialog = new SaturnFormDataDialogForDoubleClick(Display.getDefault().getShells()[0], attribute);
		dialog.open();
		tableViewer_2.refresh();
	}

	private void orderFormData(List<SaturnAttribute> list) {
		for (int i = 0; i < list.size(); i++) {
			FormDataAttribute form = (FormDataAttribute) list.get(i);
			form.setId("" + (i + 1)); //$NON-NLS-1$
		}
	}
	
	private void copyFormDataList(List<SaturnAttribute> list) {
		List<SaturnAttribute> formDataTemps = new ArrayList<SaturnAttribute>();
		for (SaturnAttribute saturn : list) {
			FormDataAttribute formData = new FormDataAttribute(
					(FormDataAttribute) saturn);
			formDataTemps.add(formData);
		}
		this.formDataTemp = formDataTemps;
	}
	
	private void initial() {
		// 基本信息选项卡
		activityIdText.setText(saturnSubActivityNode.getId().trim());
		activityNameText.setText(saturnSubActivityNode.getName().trim());
		descriptionText.setText(saturnSubActivityNode.getDescription());

		polymeModeCombo.setText(RevertCandidate.revertPolymeMode(saturnSubActivityNode.getPolymeMode().trim()));
		
		// 扩展属性选项卡
		subProcessText.setText(saturnSubActivityNode.getSubProcess().trim());
		transferModeCombo.setText(RevertCandidate.revertTransferStyle(saturnSubActivityNode.getTransferMode().trim()));
		
		// 参数选项卡(FormData)
		tableViewer_2.setInput(formDataTemp);
	}
	
	@Override
	protected void buttonPressed(int buttonId) {
		if (saturnSubActivityNode == null) {
			return;
		}
		if (buttonId == IDialogConstants.OK_ID) {
			// 基本信息
			saturnSubActivityNode.setName(activityNameText.getText().trim());
			saturnSubActivityNode.setDescription(descriptionText.getText().trim());
			saturnSubActivityNode.setPolymeMode(RevertCandidate.revertFromFaceToVO(polymeModeCombo.getText().trim()));
			saturnSubActivityNode.setTransferMode(RevertCandidate.revertFromFaceToVO(transferModeCombo.getText().trim()));
			// 扩展属性选项卡
			saturnSubActivityNode.setSubProcess(subProcessText.getText().trim());
			// 参数选项卡(FormData)
			saturnSubActivityNode.setFormDataAttributeList(formDataTemp);
		}
		super.buttonPressed(buttonId);
	}
	
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		super.createButtonsForButtonBar(parent);
		getButton(IDialogConstants.OK_ID).setEnabled(false);
	}
	
	class GUIUpdater implements Runnable {
		private IProgressMonitor monitor;

		GUIUpdater(IProgressMonitor monitor) {
			this.monitor = monitor;
		}

		public void run() {
			for (int i = 0; i < 34; i++) {
				try {
					Thread.sleep(800);
					this.monitor.worked(5);
					if (serach == true) {
						this.monitor.worked(100);
						break;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
